<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>regExp</title>
	<style type="text/css">
	* {
		padding: 0;
		margin: 0;
	}
	span.red{
		color: red;
	}
    </style>
</head>
<body>
	<div class="container" id="container">
		<h1>regExp</h1> 
		<p>用于将内容视为多行匹配，主要是对 ^和 $ 的修饰</p>
	</div>
	<script type="text/javascript">
		var hd = `
	  #1 js,200元 #
	  #2 php,300元 #
	  #9 houdunren.com # 后盾人
	  #3 node.js,180元 #
	`;
	// [{name:'js',price:'200元'}]
	var reg = /#\d+\s+(.+?)\s*#/si
	 
getRegData(reg)
// getRegModifiers(reg)

	/**
	 * 获取正则表达式 pattern, modifiers 两部分的内容
	 * @param  {[type]} reg [description]
	 * @return {[type]}     [description]
	 */
	function getRegData(reg) {
		if(!reg instanceof RegExp) {
			throw new TypeError('first argument must be an regExp object')
		}

		var regStr = reg.toString()
		var pos = regStr.lastIndexOf('/')

		var modifiers = regStr.substr(pos+1)

		// var pattern = regStr.substring(1, pos)
		var pattern = reg.source

		console.log('modifiers = ',  modifiers)
		console.log('pattern = ',  pattern)
		console.log(  reg.source)
		console.log(  regStr.substring(1, pos))
		
		return {
			pattern,
			modifiers
		}		
	}
	

	function getRegModifiers(reg) {
		return getRegData(reg)['modifiers']
	}



	
	</script>
</body>
</html>